import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JFrame;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;

/*cse 2101 Wiley Shi
 * 
 * This program follows the swing tutorial on swing Jbuttons
 * The Changes made to this program is that the middle button is now a smiley face icon and 
 * when the middle button is pressed the smiley icon will change into a laughing icon
*/
public class SwingButtons extends JPanel implements ActionListener {
	JButton b1, b2, b3;

	public SwingButtons() {
		b1 = new JButton("Disable middle button");
		b1.setMnemonic(KeyEvent.VK_D);
		b1.setActionCommand("disable");

		b2 = new JButton(/*"Middle button"*/);
		b2.setMnemonic(KeyEvent.VK_M);
		b2.setIcon(new ImageIcon("happyface.jpeg"));
		b2.setPressedIcon(new ImageIcon("happyface.gif"));
		b2.setDisabledIcon(new ImageIcon("sadface.gif"));

		b3 = new JButton("Enable middle button");
		b3.setMnemonic(KeyEvent.VK_E);
		b3.setEnabled(false);

		b1.addActionListener(this);
		b3.addActionListener(this);

		add(b1);
		add(b2);
		add(b3);
	}

	public void actionPerformed(ActionEvent e) {
		if ("disable".equals(e.getActionCommand())) {
			b2.setEnabled(false);
			b1.setEnabled(false);
			b3.setEnabled(true);
		} else {
			b2.setEnabled(true);
			b1.setEnabled(true);
			b3.setEnabled(false);
		}

	}

	private static void createAndShowGui() {
		JFrame frame = new JFrame("ButtonDemo");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		SwingButtons newContentPane = new SwingButtons();
		newContentPane.setOpaque(true);
		frame.setContentPane(newContentPane);

		frame.pack();
		frame.setVisible(true);
	}

	public static void main(String[] args) {
		javax.swing.SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				createAndShowGui();
			}
		});

	}

}
